//
//  CNBBSListCell.m
//  CsdnPlus
//
//  Created by 孟瑞瑞 on 2018/5/29.
//  Copyright © 2018年 CSDN. All rights reserved.
//

#import "CNBBSListCell.h"
#import <CNBaseTool/CNCategoryHeader.h>
#import <CNBaseViewTool/CNNoDataView.h>
#import <CNBaseViewTool/UIView+CNEmpty.h>
#import <CNBaseViewTool/CNRefreshGifHeader.h>
#import <CNBaseViewTool/CNRefreshAutoNormalFooter.h>
#import <CNBaseViewTool/CNViewConst.h>
@implementation CNBBSListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(YYLabel *)titleLb
{
    if (!_titleLb) {
        _titleLb = [[YYLabel alloc]init];
        //_titleLb.theme_textColor = cellTitleTextColorPicker;
        _titleLb.textColor = navigationBarTitleColor;
        _titleLb.displaysAsynchronously = NO;
        _titleLb.preferredMaxLayoutWidth = kWindowW - 32;
        _titleLb.font = [UIFont boldSystemFontOfSize:16];
        _titleLb.numberOfLines = 0;
        [self.contentView addSubview:_titleLb];
        [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(12);
            make.left.mas_equalTo(16);
            make.right.mas_equalTo(-16);
        }];
    }
    return _titleLb;
}

-(YYLabel *)descriptionLb
{
    if (!_descriptionLb) {
        _descriptionLb = [[YYLabel alloc]init];
        _descriptionLb.numberOfLines = 1;
        _descriptionLb.displaysAsynchronously = NO;
        _descriptionLb.preferredMaxLayoutWidth = kWindowW - 32;
        //_descriptionLb.theme_textColor = cellDesTitleTextColorPicker;
        _descriptionLb.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_descriptionLb];
        [_descriptionLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self.titleLb);
            make.top.mas_equalTo(self.titleLb.mas_bottom).mas_equalTo(4);
        }];
    }
    return _descriptionLb;
}

- (UIButton *)headImageBtn
{
    if (!_headImageBtn) {
        _headImageBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _headImageBtn.layer.allowsEdgeAntialiasing = YES;
        [_headImageBtn setEnlargeEdge:15];
        [self.contentView addSubview:_headImageBtn];
        [_headImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.titleLb);
            make.top.mas_equalTo(self.descriptionLb.mas_bottom).mas_equalTo(8);
            make.size.mas_equalTo(CGSizeMake(16, 16));
            make.bottom.mas_equalTo(-12);
        }];
        
        @weakify(self);
        [_headImageBtn bk_addEventHandler:^(id sender) {
            @strongify(self);
            if (self.delegate && [self.delegate respondsToSelector:@selector(cellDidClickHeadImage:)])
            {
                [self.delegate cellDidClickHeadImage:self];
            }
            
        } forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _headImageBtn;
}

-(UILabel *)fromLb
{
    if (!_fromLb) {
        _fromLb = [[UILabel alloc]init];
        _fromLb.numberOfLines = 1;
        _fromLb.theme_textColor = focusLogingTextColorPicker;
        _fromLb.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_fromLb];
        [_fromLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.headImageBtn.mas_right).mas_equalTo(4);
            make.centerY.mas_equalTo(self.headImageBtn);
        }];
    }
    return _fromLb;
}

-(UILabel *)forumLb
{
    if (!_forumLb) {
        _forumLb = [[UILabel alloc]init];
        _forumLb.font = [UIFont systemFontOfSize:12];
        _forumLb.numberOfLines = 1;
        [self.contentView addSubview:_forumLb];
        [_forumLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.headImageBtn);
            make.left.mas_equalTo(self.fromLb.mas_right).mas_equalTo(12);
        }];
    }
    return _forumLb;
}

-(UILabel *)timeLb
{
    if (!_timeLb) {
        _timeLb = [[UILabel alloc]init];
        _timeLb.numberOfLines = 1;
        _timeLb.theme_textColor = cellDesTitleTextColorPicker;
        _timeLb.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_timeLb];
        [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.forumLb.mas_right).mas_equalTo(12);
            make.centerY.mas_equalTo(self.headImageBtn);
            make.right.mas_lessThanOrEqualTo(self.scoreLb.mas_left).mas_offset(-12);
        }];
    }
    return _timeLb;
    
}

-(UILabel *)commentLb
{
    if (!_commentLb) {
        _commentLb = [[UILabel alloc]init];
        _commentLb.numberOfLines = 1;
        _commentLb.theme_textColor = cellDesTitleTextColorPicker;
        _commentLb.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_commentLb];
        [_commentLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.timeLb.mas_right).mas_equalTo(12);
            make.centerY.mas_equalTo(self.headImageBtn);
            make.right.mas_lessThanOrEqualTo(self.scoreLb.mas_left).mas_offset(-12);
        }];
    }
    return _commentLb;
    
}

-(UILabel *)scoreLb
{
    if (!_scoreLb) {
        _scoreLb = [[UILabel alloc]init];
        _scoreLb.numberOfLines = 1;
        _scoreLb.theme_textColor = bbsListScoreTextColorPicker;
        _scoreLb.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_scoreLb];
        [_scoreLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
            make.centerY.mas_equalTo(self.headImageBtn);
        }];
    }
    return _scoreLb;
}


-(UIImageView *)commentImageView
{
    if (!_commentImageView) {
        _commentImageView = [[UIImageView alloc]init];
        
        [self.contentView addSubview:_commentImageView];
        [_commentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.commentLb.mas_left).mas_equalTo(-4);
            make.centerY.mas_equalTo(self.headImageBtn);
            make.size.mas_equalTo(CGSizeMake(16, 16));
        }];
    }
    return _commentImageView;
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.theme_backgroundColor = cellLineBGColorPicker;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(0.5);
            make.bottom.mas_equalTo(-0.3);
        }];
    }
    return _lineView;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.theme_backgroundColor = pageBGColorPicker;
        self.contentView.theme_backgroundColor = pageBGColorPicker;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        // 设置优先级
        [self.fromLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
        [self.forumLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
        [self.commentLb setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
        [self.scoreLb setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
        [self.commentImageView setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
        
    }
    return self;
}

@end
